//
//  FindDetailVC.m
//  K8彩票
//
//  Created by zyn on 2017/6/7.
//  Copyright © 2017年 zhoubo. All rights reserved.
//

#import "FindDetailVC.h"
#import "ViewController.h"
#import "KuaiSanDetailCell.h"
#import "ShuangSeQiuDetailCell.h"
#import "PaiLie5DetailCell.h"

/// 双色球11 大乐透14 排列三16 排列五17 江苏快三75 湖北快三80 安徽快三 76
@interface FindDetailVC ()<UITableViewDelegate,UITableViewDataSource>{
    NSMutableArray *arrayDatas; // 开奖数据源
}
@property (weak, nonatomic) IBOutlet UILabel *labelTitle;
@property (weak, nonatomic) IBOutlet UITableView *tableview;

@end

@implementation FindDetailVC
@synthesize caipiaoType;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeView];
    [self initializeData];
}

-(void)initializeView{
    ((ViewController *)[UIApplication sharedApplication].keyWindow.rootViewController).mainTabbar.frame = CGRectMake(0, -49, 0, 0);
    
//        ((ViewController *)[UIApplication sharedApplication].keyWindow.rootViewController).mainTabbar.hidden = YES;
    
    switch ([caipiaoType integerValue]) {
        case 11:
            _labelTitle.text = NSLocalizedString(@"双色球", @"双色球");
            break;
            
        case 14:
            _labelTitle.text = NSLocalizedString(@"大乐透", @"大乐透");
            break;
            
        case 16:
            _labelTitle.text = NSLocalizedString(@"排列三", @"排列三");
            break;
            
        case 17:
            _labelTitle.text = NSLocalizedString(@"排列五", @"排列五");
            break;
            
        case 75:
            _labelTitle.text = NSLocalizedString(@"江苏快三", @"江苏快三");
            break;
            
        case 80:
            _labelTitle.text = NSLocalizedString(@"湖北快三", @"湖北快三");
            break;
            
        default:
            break;
    }
}

-(void)initializeData{
    arrayDatas = [NSMutableArray arrayWithCapacity:0];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSelectionStyleNone;
    
    switch ([caipiaoType integerValue]) {
        case 75:
            [self requestCaipiaoList:@{@"appkey":APP_KEY,@"caipiaoid":@"75",@"issueno":@"",@"start":@"0",@"num":@"20"} caipiaoid:75]; // 江苏快三
            break;
            
        case 80:
            [self requestCaipiaoList:@{@"appkey":APP_KEY,@"caipiaoid":@"80",@"issueno":@"",@"start":@"0",@"num":@"20"} caipiaoid:80]; // 湖北快三
            break;
            
        case 17:
            [self requestCaipiaoList:@{@"appkey":APP_KEY,@"caipiaoid":@"17",@"issueno":@"",@"start":@"0",@"num":@"20"} caipiaoid:17]; // 排列五
            break;
            
        case 16:
            [self requestCaipiaoList:@{@"appkey":APP_KEY,@"caipiaoid":@"16",@"issueno":@"",@"start":@"0",@"num":@"20"} caipiaoid:16]; // 排列三
            break;
            
        case 11:
                [self requestCaipiaoList:@{@"appkey":APP_KEY,@"caipiaoid":@"11",@"issueno":@"",@"start":@"0",@"num":@"20"} caipiaoid:11]; // 双色球
            break;
            
        case 14:
                [self requestCaipiaoList:@{@"appkey":APP_KEY,@"caipiaoid":@"14",@"issueno":@"",@"start":@"0",@"num":@"20"} caipiaoid:14]; // 大乐透
            break;
            
        default:
            break;
    }
    
}

- (IBAction)onClickBack:(id)sender {
    [self back];
}

#pragma mark - tableview
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return arrayDatas.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    switch ([caipiaoType integerValue]) {
        case 11:
            // 双色球
            
        {
            ShuangSeQiuDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShuangSeQiuDetailCell"];
            if (cell == nil) {
                cell = [[[NSBundle mainBundle]loadNibNamed:@"ShuangSeQiuDetailCell" owner:self options:nil]firstObject];
            }
            //            [cell setContentJiangSuKuai3:arrayJiangSuKuai3];
            [cell setContentShuangSeQiu:arrayDatas[indexPath.row]];
            return cell;
        }

            break;
            
        case 14:
            // 大乐透
        {
            ShuangSeQiuDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShuangSeQiuDetailCell"];
            if (cell == nil) {
                cell = [[[NSBundle mainBundle]loadNibNamed:@"ShuangSeQiuDetailCell" owner:self options:nil]firstObject];
            }
            //            [cell setContentJiangSuKuai3:arrayJiangSuKuai3];
            [cell setContentDaLeTou:arrayDatas[indexPath.row]];
            return cell;
        }
            break;
            
        case 16:
            // 排列三
            
        {
            PaiLie5DetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PaiLie5DetailCell"];
            if (cell == nil) {
                cell = [[[NSBundle mainBundle]loadNibNamed:@"PaiLie5DetailCell" owner:self options:nil]firstObject];
            }
            [cell setContentPaiLie3:arrayDatas[indexPath.row]];
            return cell;
        }
            break;
            
        case 17:
            // 排列五
        {
            PaiLie5DetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PaiLie5DetailCell"];
            if (cell == nil) {
                cell = [[[NSBundle mainBundle]loadNibNamed:@"PaiLie5DetailCell" owner:self options:nil]firstObject];
            }
            [cell setContentPaiLie5:arrayDatas[indexPath.row]];
            return cell;
        }
            break;
            
        case 75:
            // 江苏快三
        {
            KuaiSanDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KuaiSanDetailCell"];
            if (cell == nil) {
                cell = [[[NSBundle mainBundle]loadNibNamed:@"KuaiSanDetailCell" owner:self options:nil]firstObject];
            }
            [cell setContentJiangSuKuai3:arrayDatas[indexPath.row]];
            return cell;
        }
            break;
            
        case 80:
            // 湖北快三
        {
            KuaiSanDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KuaiSanDetailCell"];
            if (cell == nil) {
                cell = [[[NSBundle mainBundle]loadNibNamed:@"KuaiSanDetailCell" owner:self options:nil]firstObject];
            }
            [cell setContentJiangSuKuai3:arrayDatas[indexPath.row]];
            return cell;
        }
            break;
            
        default:
            break;
    }
    
    return nil;
    
    
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
        return 44;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


/// 请求开奖信息列表
/// 双色球11 大乐透14 排列三16 排列五17 江苏快三75 湖北快三80
- (void)requestCaipiaoList:(NSDictionary *)parameters caipiaoid:(NSInteger )caipiaoid{
    [self showHudInView:self.view hint:@""];
    [[HttpManager getInstance]get:URL_HSITORY params:parameters successCallback:^(NSString *state, id responseObject) {
        
        NSDictionary *result = [responseObject objectForKey:@"result"];
        NSArray *list = [result objectForKey:@"list"];
        for (NSDictionary *dic in list) {
            CaipiaoHistoryModel *model = [[CaipiaoHistoryModel alloc]initWithDictionary:dic];
            [arrayDatas addObject:model];
        }
        
        [_tableview reloadData];
        [self hideHud];
        
    } failCallback:^(NSString *state, id responseObject) {
        [self hideHud];
    }];
}











@end
